package com.jsaber.dockerhw.controller;


import com.jsaber.dockerhw.model.common.Response;
import com.jsaber.dockerhw.model.po.Student;
import com.jsaber.dockerhw.model.request.AddStudentRequest;
import com.jsaber.dockerhw.service.SutdentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private SutdentService sutdentService;

    @GetMapping("/all")
    public Response<List<Student>> getAll(){
        List<Student> result = sutdentService.getAll();
        return new Response<>(result);
    }

    @GetMapping("/deleteone/{id}")
    public Response<String> deleteOne(@PathVariable("id") Integer id){
        String result = sutdentService.deleteOne(id);
        return new Response<>(result);
    }

    @GetMapping("/update/{id}/{stuid}")
    public Response<String> updateOne(@PathVariable("id") Integer id, @PathVariable("stuid") String stuid){
        String result = sutdentService.updateStudent(stuid,id);
        return new Response<>(result);
    }

    @PostMapping("/add")
    public Response<String> addOne(@RequestBody AddStudentRequest request){
        String result =  sutdentService.insertOne(request);
        return new Response<>(result);
    }
}
